Significant Events Endpoint for Article as a Living Document experiment#2
Significant Events Endpoint for Article as a Living Document experiment#2tonisevener wants to merge 50 commits intomasterfrom
Conversation
Update master
…ng section detection)
…ther in one timeline event
This reverts commit f719ae1.
joewalsh
left a comment
There was a problem hiding this comment.
Looking great overall! Just found one minor issue
routes/page/significant-events.js
Outdated
| var titleDict = domainDict[keyTitle]; | ||
| if (titleDict) { | ||
| titleDict[item.revid] = item; | ||
| titleDict.maxedOut = calculateCacheForTitleIsMaxedOut(titleDict); |
There was a problem hiding this comment.
This titleDict is a copy of the value inside domainDict so updating it doesn't update the value inside of domainDict. This could be fixed by moving domainDict[keyTitle] = titleDict; outside of the if/else block so that the updated value is set in the domainDict in either case. I'm not sure if there's a way to get reference semantics here so you could update directly
routes/page/significant-events.js
Outdated
| titleDict[item.revid] = item; | ||
| titleDict.maxedOut = calculateCacheForTitleIsMaxedOut(titleDict); | ||
| domainDict[keyTitle] = titleDict; | ||
| } |
There was a problem hiding this comment.
Same comment as above but for the domainDict, should be fixed by moving significantChangesCache[req.params.domain] = domainDict; below out of the if/else block
|
|
||
| return Object.assign({ | ||
| uncachedRevisions: uncachedRevisions, | ||
| cachedOutput: cachedOutput |
There was a problem hiding this comment.
I noticed cachedOutput is always empty, even on subsequent requests for the same title. Seems to be fixed by making the changes suggested below
routes/page/significant-events.js
Outdated
| domainDict = {}; | ||
| domainDict[keyTitle] = titleDict; | ||
| significantChangesCache[req.params.domain] = domainDict; | ||
| } |
There was a problem hiding this comment.
Given the comments above, and that || in JS works kind of like ?? in Swift, this could be updated to:
function setSignificantChangesCache(req, title, item) {
const keyTitle = keyTitleForCache(req, title);
var domainDict = significantChangesCache[req.params.domain] || {};
var titleDict = domainDict[keyTitle] || {};
titleDict[item.revid] = item;
titleDict.maxedOut = calculateCacheForTitleIsMaxedOut(titleDict);
domainDict[keyTitle] = titleDict;
significantChangesCache[req.params.domain] = domainDict;
}
routes/page/significant-events.js
Outdated
| } | ||
|
|
||
| // clean out from talk page cache | ||
| // todo: why on earth do we get a talkPageTitle is not a function error here? |
There was a problem hiding this comment.
If you had:
var talkPageTitle = talkPageTitle(req);the function is already shaded by the variable name. Could be fixed by renaming the function to getTalkPageTitle or using a different variable name
…nupCache Change-Id: Ia2b76a7bfc63f34dccfb678a27ae42287c6d0c96
Change-Id: I9c5f795e76d4564022cdd79a53162e5672d16bd8
…solutely necessary
https://phabricator.wikimedia.org/T241253